<template>
<!-- 事件： on https://www.bilibili.com/video/BV1hb411K7Ud?p=28&spm_id_from=pageDriver 三分钟详细讲解
       ！！！ onmouseover="" onmouseout=""  嵌套div，对父级使用这两个属性，从父级进入子级就会出发out属性！！！
        -->
  <li @mouseenter="handleEnter(true)" @mouseleave="handleEnter(false)" :style="{background:bgColor}">
    <label>
      <input type="checkbox" v-model="item.complete"/>
      <span>{{ item.title }}</span>
    </label>
    <button class="btn btn-danger" v-show="isShow" @click="deleteItem(index)">删除</button>
  </li>
</template>

<script>
export default {
  name: "TodoItem",
  props:['item','index'],
  data(){
    return{
      bgColor:'white',
      isShow:false,
    }
  },
  methods:{
    handleEnter(isEnter){
      if (isEnter){
        this.bgColor = 'gray';
        this.isShow = true;
      }else{
        this.bgColor = 'white';
        this.isShow = false;
      }
    },
    deleteItem(index){
      this.$store.dispatch('deleteTodo',index)
      /*if (window.confirm('你将删除' + this.item.title)){
        this.removeToDo(index)
      }*/
    }
  }
}
</script>

<style scoped>
/*item*/
li {
  list-style: none;
  height: 36px;
  line-height: 36px;
  padding: 0 5px;
  border-bottom: 1px solid #ddd;
}

li label {
  float: left;
  cursor: pointer;
}

li label li input {
  vertical-align: middle;
  margin-right: 6px;
  position: relative;
  top: -1px;
}

li button {
  float: right;
  margin-top: 3px;
}

li:before {
  content: initial;
}

li:last-child {
  border-bottom: none;
}

</style>
